<template>
  <div class="order-confirm">
    <van-row v-for="cart of checkedCartList">
      <van-col span="6">
        <van-image
            width="50px"
            height="50px"
            fit="fill"
            :src="cart.foodMainImage"
        />
      </van-col>
      <van-col span="10">
        <div class="name">{{ cart.foodName }}</div>
        <div class="price">￥{{ cart.foodPrice }}</div>
      </van-col>
      <van-col span="6" class="count-wrapper">
        <!--        <van-stepper v-model="cart.quantity" :name="cart.id" theme="round" button-size="22" disable-input-->
        <!--                     @change="handleQuantityChange"/>-->
        <span class="count">{{ cart.quantity }}</span>
      </van-col>
    </van-row>

    <van-address-list
        v-model="chosenAddressId"
        :list="deliveryAddressList"
        default-tag-text="默认"
    />

    <van-button type="primary" block @click="handleCreateOrder">提交订单</van-button>

  </div>
</template>

<script>
import {showDialog} from "vant";

export default {
  name: "confirm",
  data() {
    return {
      checkedCartList: [],
      chosenAddressId: 1,
      deliveryAddressList: []
    }
  },
  methods: {
    _initDeliveryAddressList() {
      this.$axios.get('/ele_server/order/deliveryAddressList').then(({data: res}) => {
        if (res.status == 0) {
          for (let item of res.data) {
            this.deliveryAddressList.push({
              id: item.id,
              name: item.contactName,
              tel: item.phone,
              address: item.address
            })
          }
          this.deliveryAddressList[0].isDefault = true;
          this.chosenAddressId = this.deliveryAddressList[0].id
        } else if (res.status == 3003) {
          showDialog({
            title: '提示',
            message: '当前未登录',
            theme: 'round-button',
            confirmButtonText: '去登录'
          }).then(() => {
            this.$router.push('/user/login?redirect=/order/confirm');
          });
        } else {}
      })
    },
    handleCreateOrder() {
      console.log(this.chosenAddressId)
    }
  },
  created() {
    this.checkedCartList = JSON.parse(localStorage.getItem('setCheckedCartList'))
    this._initDeliveryAddressList();
  }
}
</script>

<style scoped lang="stylus">
  .order-confirm
    >>>.van-address-list
      .van-address-list__bottom
        position relative
</style>